﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AdaptiveDeNet;
using AdaptiveDeNet.Functions;
using AdaptiveDeNet.RAND;
using System.Diagnostics;
using AdaptiveDeNet.CSV;
using Konzole.Test;
using System.Threading.Tasks;
using System.Threading;
using System.IO;
using AdaptiveDeNet.DifferentialEvolution;
using AdaptiveDeNet.Bechmark;
//using AdaptiveDeNet.b6e6rl;

namespace Konzole
{
    public class Program
    {
        static void Main(string[] args)
        {

            int N = 60;
            int dim = 30;

            double F = 0.5;
            double Cr = 0.5;

            double[] lowerBound = new double[dim];
            double[] upperBound = new double[dim];

            Function fEval = new Ackley(upperBound, lowerBound);

            for (int i = 0; i < lowerBound.Length; i++)
            {
                lowerBound[i] = -2.048;
            }

            for (int i = 0; i < upperBound.Length; i++)
            {
                upperBound[i] = 2.048;
            }

            List<Result> results = new List<Result>();

            for (int i = 0; i < 5; i++)
            {
                AdaptiveDeNet.DifferentialEvolution.MultiThreaded.Optimizer optimizer = new AdaptiveDeNet.DifferentialEvolution.MultiThreaded.Optimizer(fEval);

                //Result result = optimizer.de_b6e6rl(lowerBound, upperBound, 20000 * dim, dim, N, 0.000001, 2, 1 / 60.0);
                Result result = optimizer.de_rand_1_bin(F, Cr, lowerBound, upperBound, 20000 * dim, dim, N, 0.000001);

                results.Add(result);

            }

            CSVwriter writer = new CSVwriter();

            writer.WriteResults("TEST(dim=" + dim + ")", results);


            //CEC14Benchmark bench = new CEC14Benchmark();

            ////bench.JADEBench();
            ////bench.JADEParallelBench();
            //bench.JADEParallelBench();
            //bench.b6e6rlBenchParallel();
            //bench.b6e6rlBench();

            Console.WriteLine("completed");
            


            
        }

        private static void Rosen(int dim)
        {
            //int N = 5 * dim; //velikost populace
            int N = 60;

            double F = 0.5;
            double Cr = 0.5;

            double[] lowerBound = new double[dim];// { -500, -500, -500, -500, -500, -500, -500, -500, -500, -500 };
            double[] upperBound = new double[dim];// { 500, 500, 500, 500, 500, 500, 500, 500, 500, 500 };

            Function fEval = new Dejong2();

            for (int i = 0; i < lowerBound.Length; i++)
            {
                lowerBound[i] = -2.048;
            }

            for (int i = 0; i < upperBound.Length; i++)
            {
                upperBound[i] = 2.048;
            }

            List<Result> results = new List<Result>();

            for (int i = 0; i < 100; i++)
            {
                //DEpara solver = new DEpara(fEval);
                //DE.DE solver = new DE.DE(fEval);
                //DE.DeRand1Exp.DE solver = new DE.DeRand1Exp.DE(fEval);
                //DE.b6e6rl.b6e6rl solver = new DE.b6e6rl.b6e6rl(fEval);
                //DE.b6e6rlParallel.b6e6rl solver = new DE.b6e6rlParallel.b6e6rl(fEval);
                //DE.JADEparallel.JADE solver = new DE.JADEparallel.JADE(fEval);


                //AdaptiveDeNet.JDEParallel.jDE solver = new AdaptiveDeNet.JDEParallel.jDE(fEval);

                //JADE solver = new JADE(fEval);

                Stopwatch sw = new Stopwatch();
                sw.Start();

                //results.Add(solver.deJADE(lowerBound, upperBound, 20000 * dim, dim, N, 0.000001, 0.1 ,0.05));
                //results.Add(solver.de_rand_1_bin(F, Cr, lowerBound, upperBound, 20000 * dim, dim, N, 0.000001));
                //results.Add(solver.jDE(lowerBound, upperBound, 20000 * dim, dim, N, 0.000001,0.1,0.1));
                //results.Add(solver.de_b6e6rl(F, Cr, lowerBound, upperBound, 20000 * dim, dim, N, 0.000001, 2, 1 / 60.0));

                sw.Stop();

                results[i].Elapsed = sw.ElapsedMilliseconds;
                sw.Reset();
            }

            CSVwriter writer = new CSVwriter();

            writer.WriteResults("Rosen(dim=" + dim + ")", results);
        }
    }
}
